package maple.thelittleredbook.content.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;
import maple.thelittleredbook.content.entity.Image;

import java.util.List;

/**
 * 图片Mapper接口
 */
@Mapper
public interface ImageMapper extends BaseMapper<Image> {

    /**
     * 根据内容ID查询图片列表
     */
    @Select("SELECT id, content_id, image_url, created_at FROM images WHERE content_id = #{contentId} ORDER BY created_at ")
    List<Image> selectByContentId(@Param("contentId") Long contentId);

    /**
     * 根据图片ID删除图片记录
     */
    @Delete("DELETE FROM images WHERE id = #{imageId}")
    void deleteById(@Param("imageId") Long imageId);

    /**
     * 根据图片ID查询图片记录
     */
    @Select("SELECT id, content_id, image_url, created_at FROM images WHERE id = #{imageId}")
    Image selectByImageId(@Param("imageId") Long imageId);

    /**
     * 统计内容的图片数量
     */
    @Select("SELECT COUNT(*) FROM images WHERE content_id = #{contentId}")
    Long countByContentId(@Param("contentId") Long contentId);

}